<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateGoldSplitsTable extends Migration
{
    public function up()
    {
        Schema::create('gold_splits', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->default(0)->index();
            $table->unsignedBigInteger('gold_round_id')->default(0)->index();
            $table->unsignedBigInteger('gold_seed_id')->default(0);
            $table->unsignedBigInteger('gold_product_id')->default(0)->index();
            $table->unsignedBigInteger('product_id')->default(0);
            $table->unsignedBigInteger('product_sku_id')->default(0);
            $table->unsignedBigInteger('split_record_id')->default(0)->index();
            $table->unsignedBigInteger('settled_record_id')->default(0)->index();
            $table->unsignedBigInteger('new_gold_product_id')->default(0)->index();
            $table->unsignedInteger('round')->default(0);
            $table->string('gold_seed_title')->nullable();
            $table->string('product_title')->nullable();
            $table->string('sku_name')->nullable();

            $table->decimal('split_price', 10, 2)->default(0)->comment('paid net price');
            $table->decimal('split_profit', 10, 2)->default(0);
            $table->decimal('split_beans', 10, 2)->default(0)->comment('paid gold beans');

            $table->dateTime('started_at')->nullable()->comment('start selling');
            $table->dateTime('settled_at')->nullable()->index()->comment('settle up split record');

            $table->timestamps();

            $table->index(['created_at']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('gold_splits');
    }
}
